<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>学员管理</title>
<link rel="stylesheet" type="text/css"
	href="/ExamOnline/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="/ExamOnline/easyui/themes/icon.css">
<script type="text/javascript" src="/ExamOnline/easyui/jquery.min.js"></script>
<script type="text/javascript"
	src="/ExamOnline/easyui/jquery.easyui.min.js"></script>

</head>

<body>
	<table id="dg" width="600"></table>


	<div id="w" class="easyui-window" title="修改学员信息"
		data-options="modal:true,closed:true,iconCls:'icon-save'"
		style="width:500px;padding:10px;">
		<form id="ff" method="post">
			<input type="hidden" name="userid" />
			<table cellpadding="5">
				<tr>
					<td>学员名称:</td>
					<td><input class="easyui-textbox" type="text" name="name"
						data-options="required:true"></input></td>
				</tr>
				<tr>
					<td>密码:</td>
					<td><input class="easyui-textbox" name="pwd" type="password"
						data-options="required:true"></input></td>
				</tr>
				<tr>
					<td>阶段:</td>
					<td><select name="stage" class="easyui-combobox"
						panelHeight="auto">
							<option value="1">一阶段</option>
							<option value="2">二阶段</option>
							<option value="3">三阶段</option>
							<option value="4">四阶段</option>
					</select></td>
				</tr>
				<tr>
					<td>状态:</td>
					<td><select name="status" class="easyui-combobox"
						panelHeight="auto">
							<option value="1">正常</option>
							<option value="2">重修</option>
					</select></td>
				</tr>
				<tr>
					<td>入学时间:</td>
					<td><input id="dd" name="entrancetime" type="text"
						class="easyui-datebox" required="required"></td>
				</tr>
				<tr>
					<td colspan="2">
						<div style="text-align:center;padding:5px">
							<a href="javascript:void(0)" class="easyui-linkbutton"
								iconCls="icon-ok" onclick="saveUser()">保存</a> <a
								href="javascript:void(0)" class="easyui-linkbutton"
								iconCls="icon-cancel"
								onclick="javascript:$('#w').dialog('close')">取消</a>
						</div>
					</td>
				</tr>
			</table>
		</form>
	</div>

</body>
<script>
	$("#dg").datagrid({
		url : '/ExamOnline/user/list',
		rownumbers : 'true',
		autoRowHeight : 'false',
		method : 'get',
		toolbar : '#tb',
		loadMsg : '正在加载',
		pagination : 'true', //pagination将发送两个参数到服务器：page：页码，起始值 1。rows：每页显示行。
		pageSize : 5,//每页显示的记录条数，默认为10 ,不可单独设置该属性，要与pageList一起设置。
		pageList : [ 5, 10, 15 ],//可以设置每页记录条数的列表 
		fitColumns : 'true',
		singleSelect : 'true',
		columns : [ [ {
			field : 'name',
			title : '学员名称',
			align : 'center'
		}, {
			field : 'stage',
			title : '阶段',
			width : 30,
			align : 'center',
			formatter : function(value, row, index) {
				if (value == 1) {
					return "一阶段";
				} else if (value == 2) {
					return "二阶段";
				} else if (value == 3) {
					return "三阶段";
				} else if (value == 4) {
					return "四阶段";
				}
			}
		}, {
			field : 'entrancetime',
			title : '入学时间',
			align : 'center',
			width : 80,
			formatter : function(value, row, index) {
				var localtime = new Date(value);
				return localtime.toLocaleDateString();
			}
		}, {
			field : 'status',
			title : '状态',
			align : 'center',
			width : 40,
			formatter : function(value, row, index) {
				if (value == 1) {
					return "正常";
				} else {
					return "重修";
				}
			}
		}, {
			field : 'test',
			title : '操作',
			align : 'center',
			formatter : formatOper
		} ] ]
	});
	//设置分页控件 
	var p = $('#dg').datagrid('getPager');
	$(p).pagination({
		beforePageText : '第',//页数文本框前显示的汉字 
		afterPageText : '页    共 {pages} 页',
		displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
	});

	function formatOper(val, row, index) {
		return "<a href='#' onclick='resetPwd(" + row.userid
				+ ")'>重置密码</a>&nbsp;<a href='#' onclick='editpanel(" + index
				+ ")'>修改</a>&nbsp;<a href='#' onclick='delpanel(" + row.userid
				+ ")'>删除</a>";
	}

	function resetPwd(id) {
		$.post("/ExamOnline/user/resetpwd", "id=" + id, function(r) {
			$.messager.alert("消息提示", r);
		});
	}
	function editpanel(index) {
		var row = $("#dg").datagrid("getRows")[index];
		var time = new Date(row.entrancetime);
		var day = time.getDate();
		var month = time.getMonth() + 1;
		var year = time.getFullYear();
		row.entrancetime = month + "/" + day + "/" + year;
		$("#ff").form("load", row);
		$('#w').window('open');

	}

	function saveUser() {
		$('#ff').form('submit', {
			url : '/ExamOnline/user/edit',
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(result) {
				$.messager.alert('提示信息', result);
				if (result == "修改成功！") {
					$('#w').dialog('close'); // close the dialog
					$('#dg').datagrid('reload'); // reload the user data
				}
			}
		});
	}

	function delpanel(id) {
		$.messager.confirm('消息提示', '您确定要删除吗？', function(r) {
			if (r) {
				$.post("/ExamOnline/user/delete", "id=" + id, function(r) {
					$.messager.alert('消息提示', r);
					$("#dg").datagrid('reload');
				});
			}
		});
	}
</script>

</html>